package com.guigu.yuhao.controller;

import com.guigu.common.service.DFileService;
import com.guigu.common.pojo.*;
import com.guigu.common.util.GetUUidUtil;
import com.guigu.common.vo.SearchVo;
import com.guigu.common.vo.module_detailsVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/designModule")
public class DFileController {

    @Resource
    private DFileService dFileService;
    @Resource
    private GetUUidUtil getUUidUtil;

    //主查询
    @RequestMapping("/Dfile")
    @ResponseBody
    public SearchVo<DFile> queryDFileall(@RequestBody SearchVo searchVo){
        return dFileService.queryDfileall(searchVo);
    }
    //查询商品
    @RequestMapping("/notMaterial")
    @ResponseBody
    public SearchVo<DFile> querynotMaterial(@RequestBody SearchVo searchVo){

        return dFileService.querynotMaterial(searchVo);
    }
    //查询物料
    @RequestMapping("/Material")
    @ResponseBody
    public SearchVo<DFile> queryMaterial(@RequestBody SearchVo searchVo){

        return dFileService.queryMaterial(searchVo);
    }
    //添加
    @RequestMapping("/add")
    @ResponseBody
    public void add(@RequestBody DFile dFile){

        String s = getUUidUtil.returnId("100");
        dFile.setProductId(s);
        dFile.setCheckTag("s001-0");
        dFile.setChangeTag("d002-0");
        dFile.setPriceChangeTag("j001-0");
        dFile.setDeleteTag("c001-0");
        dFile.setDesignModuleTag("w001-0");
        dFile.setDesignProcedureTag("g001-0");
        dFile.setDesignCellTag("k001-0");
        dFileService.insert(dFile);
    }
    //添加的查询
    @RequestMapping("/addqeury")
    @ResponseBody
    public SearchVo<DFile> addqueryDFile(@RequestBody SearchVo searchVo){

        return dFileService.addqueryDfile(searchVo);
    }
    //删除
    @RequestMapping("/remove")
    @ResponseBody
    public void remove(String id){
        dFileService.remove(id);
    }
    //彻底删除
    @RequestMapping("/deleteCompletely")
    @ResponseBody
    public void deleteCompletely(String id){
        int i=Integer.parseInt(id);
        dFileService.deleteCompletely(i);
    }
    //恢复
    @RequestMapping("/recover")
    @ResponseBody
    public void recover(String id){
        int i=Integer.parseInt(id);
        dFileService.recover(i);
    }
    @RequestMapping("/queryadmin")
    @ResponseBody
    public SysUsers queryadmin(){
        Subject subject = SecurityUtils.getSubject();
        SysUsers user = (SysUsers) subject.getSession().getAttribute("user");
        return user;
    }
    @RequestMapping("/update")
    @ResponseBody
    public void update(@RequestBody DFile dFile){

        dFile.setChangeTag("d002-1");
       dFileService.updateByPrimaryKey(dFile);
    }

    @RequestMapping("/audit")
    @ResponseBody
    public void audit(@RequestBody DFile dFile){

        dFileService.audit(dFile);
    }
    @RequestMapping("/notAudit")
    @ResponseBody
    public void notAudit(@RequestBody DFile dFile){

        dFileService.notAudit(dFile);
    }
    @RequestMapping("/addMaterial")
    @ResponseBody
    public void addMaterial(@RequestBody module_detailsVo module_details){
        dFileService.updatedesignModuleTag(module_details.getProductId());
        module_details.setDesignId(getUUidUtil.returnId("200"));
        module_details.setChangeTag("b002-0");
        module_details.setCheckTag("S001-0");
       dFileService.addMaterial(module_details);
       dFileService.adddModuleDetails(module_details);
    }

}
